// var serverUrl="http://127.0.0.1:9999";
var serverUrl="https://bill.nsshylxh.com/generator";


function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
	var context = "";
	if (r != null)
	context = r[2];
	reg = null;
	r = null;
	return context == null || context == "" || context == "undefined" ? "" : context;
}

function dealNull(val,str){
	if(!val){
		return str;
	}
	return val;
}

function serializeObject(form) {
	var o = {};
	$.each(form.serializeArray(), function(index) {
		if (o[this['name']]) {
			o[this['name']] = o[this['name']] + "," + this['value'];
		} else {
			o[this['name']] = this['value'];
		}
	});
	return o;
}

$(function(){
	$.ajaxSetup({
	    complete: function (request, status) {
	        if (typeof (request) != 'undefined') {
	        	if(request.statusText=="error"){
	        		alert("请求异常");
	        		return;
	        	}
	            var code = request.responseJSON?request.responseJSON.code:"";
	            if(code && code!=200){
	            	if(code == 403){
	            		alert(request.responseJSON.message);
	            	}else{
	            		alert(request.responseJSON.message);
	            	}
	            }
	        }
	    },
	    error: function (jqXHR, textStatus, errorThrown) {
	    	var errorText = '';
	    	if(jqXHR.responseJSON){
	    		errorText = jqXHR.responseJSON.error;
	    	}
	        switch (jqXHR.status) {
	            case (500):
	                errorText = '系统异常';
	                break;
	            case (400):
	            	errorText = '请求参数错误';
	                break;
	            case (401):
	                break;
	            case (403):
	                errorText = '您没有访问权限';
	                break;
	            case (404):
	                errorText = '请检查您的访问地址是否存在';
	                break;
	            case (405):
					errorText = '请检查您的请求方式是否错误';
	                break;
	            default:
	            	break;
	        }
	        if (jqXHR.status > 200){
	        	alert(errorText);
	        }
	    }
	});
});